package com.five.admin.service.impl;

import com.five.admin.dao.CourseClassifyMapper;
import com.five.admin.service.CourseClassifyService;
import com.five.entity.CourseClassify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: star
 * @Date: 2021-05-21 14:16
 *
 * 课程类别Service层实现类
 */
@Service
public class CourseClassifyServiceImpl implements CourseClassifyService {

    @Autowired
    private CourseClassifyMapper courseClassifyMapper;

    @Override
    public List<CourseClassify> findAll() {
        return courseClassifyMapper.findAll();
    }

    @Override
    public void insertCourseClassify(String typename) {
        courseClassifyMapper.insertCourseClassify(typename);
    }

    /**
     *
     * @return 课程类型列表
     */
    @Override
    public List<CourseClassify> getCourseClassify() {
        List<CourseClassify> list = courseClassifyMapper.selectCourseClassify();
        return list;
    }

    /**
     * 更新课程类别
     * @param courseClassify
     * @return
     */
    @Override
    public int updateCourseClassify(CourseClassify courseClassify) {
        return courseClassifyMapper.updateCourseClassify(courseClassify);
    }

    /**
     * 根据id查询课程类别
     * @param id
     * @return
     */
    @Override
    public CourseClassify findById(long id) {
        return courseClassifyMapper.findById(id);
    }

    /**
     * 根据id删除课程类别
     * @param id
     */
    @Override
    public void deleteCourseClassify(long id) {
        courseClassifyMapper.deleteCourseClassify(id);
    }

    @Override
    @Transactional
    public void deleteSelectCourseClassify(long[] ids) {
        for(int i = 0; i < ids.length; i++){
            courseClassifyMapper.deleteCourseClassify(ids[i]);
        }
    }

    /**
     * 模糊查询
     * @param typename
     * @return
     */
    @Override
    public List<CourseClassify> fuzzyQueryByTypename(String typename,int page) {
        return courseClassifyMapper.fuzzyQueryByTypename(typename,(page-1)*10);
    }

    /**
     * 计算课程类别总数
     * @return
     */
    @Override
    public int countCourseClassify(String typename) {
        return courseClassifyMapper.countCourseClassify(typename);
    }


}
